package com.ziyia.a4_5_1;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.ziyia.a4_5_1.fragment.BlankFragment;
import com.ziyia.a4_5_1.fragment.BlankFragment2;

public class MainActivity extends AppCompatActivity implements BlankFragment2.SendData{




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void frag(View view) {
        BlankFragment fragment = BlankFragment.newInstance("传递的数据");

        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction()
                .replace(R.id.frame, fragment)
                .commit();

    }

    public void frag2(View view) {
        Bundle bundle = new Bundle();
        bundle.putString("username", "年少有为");

        FragmentManager fragmentManager = getSupportFragmentManager();
        BlankFragment2 fragment2 = (BlankFragment2) fragmentManager.findFragmentById(R.id.frag2);
        fragment2.setmParam1("接收到的数据");
    }

    @Override
    public void sendMsg(String msg) {
        new AlertDialog.Builder(this)
                .setTitle(getLocalClassName())
                .setMessage(msg)
                .create()
                .show();
    }
}